package MaquinaDeEstados;

import java.awt.event.*;
import java.awt.*;

import javax.swing.*;
import javax.swing.event.*;

public class Main extends JFrame implements ActionListener {
	private int width;
	private int height;
	private int x;
	private int y;
	private int YScreen;
	private int XScreen;
	private JPanel panel;
	private JButton boton;
	private JLabel label;
	private JTextField texto;
	private String string;

	public Main() {
		this.ventana();
		this.setVentana();
	}

	public void ventana() {
		this.width = 250;
		this.height = 250;
		this.XScreen = Toolkit.getDefaultToolkit().getScreenSize().width;
		this.YScreen = Toolkit.getDefaultToolkit().getScreenSize().height;
		this.x = XScreen / 2 - width / 2;
		this.y = YScreen / 2 - height / 2;
		setLocation(x, y);
		setTitle("Window");
		setSize(width, height);
	}

	public void setVentana() {
		panel = new JPanel(new GridLayout(2, 1));
		add(panel);
		texto = new JTextField();
		boton = new JButton("Segunda palabra");
		panel.add(texto);
		panel.add(boton);
		boton.setActionCommand("Segunda palabra");
		boton.addActionListener(this);
		this.string = texto.getText();
		setVisible(true);
		this.setString();
	}

	private void setString() {

	}

	public static void main(String[] args) {
		new Main();
	}

	public void actionPerformed(ActionEvent e) {
		switch (e.getActionCommand()) {
		case "Segunda palabra":
			this.string = texto.getText();
			texto.setText("");
			boton.setText("Concatenar");
			boton.setActionCommand("Concatenar");
			break;
		case "Concatenar":
			this.string = string + texto.getText();
			texto.setText(this.string);
			boton.setEnabled(false);
			boton.setText("FIN");
			break;
		}
	}
}